package com.houdoudou.affair.jsp;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Common {

	public static void forwardToJsp(HttpServletRequest req, HttpServletResponse resp,String jspPath,String errorInfo){
		 try {
			   System.out.println("跳转到     "+jspPath+"?errorInfo="+errorInfo);			  	   
				req.getRequestDispatcher(jspPath+"?errorInfo="+errorInfo).forward(req, resp);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
	}
	
	public static void forwardToJsp(HttpServletRequest req, HttpServletResponse resp,String jspPath){
		 try {
			   System.out.println("跳转到     "+jspPath);			  	   
				req.getRequestDispatcher(jspPath).forward(req, resp);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
	}

	public static void redirectToJsp(HttpServletRequest req, HttpServletResponse resp,String jspPath,String errorInfo){
		 try {
			 
			 System.out.println("跳转到     "+jspPath+"?errorInfo="+errorInfo);	
			 errorInfo =java.net.URLEncoder.encode(errorInfo,"UTF-8");
				resp.sendRedirect(jspPath+"?errorInfo="+errorInfo);
			}  catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
	}
	
	public static void redirectToJsp(HttpServletRequest req, HttpServletResponse resp,String jspPath){
		 try {
			 System.out.println("跳转到     "+jspPath);			
				resp.sendRedirect(jspPath);
			}  catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
	}
	
	
}
